﻿Ext.define('app.prm.project_task.ImportConfirm',
{
    extend: 'Ext.window.Window',
    title: '问题导入确认',
    autoScroll: true,
    modal: true,
    width: 600,
    height: 500,
    layout: 'fit',
    trees: null,
    tasks: null,
    projectId: 0,
    initComponent: function () {
        var me = this;
        me.items = [me.getTree()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSave },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    getTree: function () {
        var me = this;
        if (!this.tree) {

            this.tree = new Ext.tree.Panel({
                border: false,
                useArrows: true,
                rootVisible: false,
                store: new Ext.data.TreeStore({
                    autoLoad: true,
                    nodeParam: 'parentId',
                    // 根节点的参数值是0
                    defaultRootId: "0",
                    proxy: {
                        type: 'memory',
                        data: me.trees,
                        reader: {
                            type: 'json',
                            rootProperty: function (node) {
                                return node.result || node.children;
                            }
                        }
                    }
                }),
                root: { id: '0', text: '' },
                listeners: {
                    afterrender: function (tree) { tree.expandAll(); }
                }
            });
        }
        return this.tree;
    },
    onSave: function () {
        var me = this;

        App.AjaxPost('/api/services/app/projectTask/ImportConfirm', { tasks: me.tasks, projectId: me.projectId }, function () {
            me.fireEvent("savesuccess");
        });
    }
});